﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ndo.Maths
{
    public class SingleFloat : Real<SingleFloat>
    {
        public SingleFloat()
            : this(1)
        { }
        public SingleFloat(Single f)
        {
            value = f;
        }

        public override bool IsNaN
        { get { return Single.IsNaN(value); } }
        public override bool IsPositiveInfinity
        { get { return Single.IsPositiveInfinity(value); } }
        public override bool IsNegativeInfinity
        { get { return Single.IsNegativeInfinity(value); } }

        private readonly Single value;
        public static explicit operator Single(SingleFloat i)
        {
            return i.value;
        }
        public static implicit operator SingleFloat(Single i)
        {
            return new SingleFloat(i);
        }
        public static SingleFloat operator +(SingleFloat i1, SingleFloat i2)
        {
            return new SingleFloat((Single)(i1.value + i2.value));
        }
        public static SingleFloat operator -(SingleFloat i1, SingleFloat i2)
        {
            return new SingleFloat((Single)(i1.value - i2.value));
        }
        public static SingleFloat operator *(SingleFloat i1, SingleFloat i2)
        {
            return new SingleFloat((Single)(i1.value * i2.value));
        }
        public static SingleFloat operator /(SingleFloat i1, SingleFloat i2)
        {
            return new SingleFloat((Single)(i1.value / i2.value));
        }
        public static SingleFloat operator %(SingleFloat i1, SingleFloat i2)
        {
            return new SingleFloat((Single)(i1.value % i2.value));
        }
        public static bool operator ==(SingleFloat i1, SingleFloat i2)
        {
            return i1.value == i2.value;
        }
        public static bool operator !=(SingleFloat i1, SingleFloat i2)
        {
            return i1.value != i2.value;
        }

        public override bool Equals(object obj)
        {
            if (obj is SingleFloat)
                return this.value == ((SingleFloat)obj).value;
            return false;
        }
        public override int GetHashCode()
        {
            return value.GetHashCode();
        }
        public override string ToString()
        {
            return value.ToString();
        }

        public override int CompareTo(SingleFloat other)
        {
            return value.CompareTo(other.value);
        }

        public override SignTypes Sign
        {
            get
            {
                if (value > 0)
                    return SignTypes.Positive;
                if (value < 0)
                    return SignTypes.Negative;
                return SignTypes.Zero;
            }
        }
    }
}
